/**
 * 表格肩部按钮click事件
 */
import {AddRow} from './commonEvent'
const areaBtnAction = window.presetVar.areaBtnAction;
const statusVar = window.presetVar.status;
const {body1, body2} = window.presetVar.body;
import { setDefautValueAfterBodyAdd } from '../initTemplate'

function tableButtonClick() {
    
    let obj = {};
    window.presetVar.bodys && window.presetVar.bodys.forEach(bodycode => {
        obj =  Object.assign(obj, {
            [bodycode + areaBtnAction.add] : () => {
                this.props.cardTable.addRow(bodycode, undefined, null, false);
            },
            [bodycode + areaBtnAction.save] : () => {
                this.props.cardTable.setStatus(bodycode, statusVar.browse);
            },
            [bodycode + areaBtnAction.edit] : () => {
                this.props.cardTable.setStatus(bodycode, statusVar.edit);
            },
            [bodycode + '_Add']: {
                afterClick: (record, index) => {
                    AddRow(this.props)
                    setDefautValueAfterBodyAdd(this.props, bodycode)
                }
            }
        })    
    });
    return obj  
}

export default tableButtonClick;